<!DOCTYPE HTML>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商之联后台管理系统</title>
  <meta name="description" content="这是一个 table 页面">
  <meta name="keywords" content="table">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="{:C('SUPPLIER_ADMIN_IMG')}favicon.png"> <link rel="apple-touch-icon-precomposed" href="{:C('SUPPLIER_ADMIN_IMG')}app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}amazeui.min.css"/>
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}admin.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->
<!-- header start-->

<include file="Public:header"/>

<!-- header end-->
<div class="am-cf admin-main">
 <!-- sidebar start -->
   <include file="Public:menu"/>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">

    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品管理</strong> / <small>商品列表</small></div>
    </div>
    <div class="am-g">
      <div class="am-u-sm-12 am-u-md-1">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
            <button type="button" class="am-btn am-btn-default"><span class="am-icon-plus"></span> <a href="{:U('Item/addItem')}">新增商品</a></button>
          </div>
        </div>
      </div>

      <div class="am-u-sm-12 am-u-md-8">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
            <span class='typetree'>
              <select name='typeid'>
              <option value=0>全部类目</option>
              </select>
            </span>
            <span class='brandtree'>
              <select name='brandid'>
              <option value=0>全部品牌</option>
              </select>
            </span>

             <span class='yid'>
             
              <input type="radio" name="yid" value="<?php echo $_SESSION['yid']?>" />自有产品
            </span>
            <span><button type="button" class="am-btn am-btn-primary am-btn-xs" id="filter">筛选</button></span>
          </div>
        </div>
      </div>

      
      <div class="am-u-sm-12 am-u-md-3">
        <div class="am-input-group am-input-group-sm">
          <input type="text" class="am-form-field" placeholder="输入产品名称 货号" name="keywords">
          <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button" id="search">搜索</button>
          </span>
        </div>
      </div>
    </div>



    <div class="am-g">
      <div class="am-u-sm-12">

          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th class="table-check"><input type="checkbox" /></th>
                <th class="table-id">ID</th>
                <th class="table-title">商品名称</th>
                <th class="table-title">商品编号</th>
                <th class="table-title">零售价</th>
                <th class="table-title">供货价</th>
                <th class="table-title">库存</th>
                <th class="table-date">生成日期</th>
                <th class="table-set">操作</th>
              </tr>
          </thead>
          <tbody>
            <foreach name="items" item='item'>
            <tr>
              <td><input type="checkbox" /></td>
              <td>{$item['itemid']}</td>
              <td>{$item['itemname']}</td>
              <td>{$item['bn']}</td>
              <td>{$item['price']}</td>
              <td>{$item['supperprice']}</td>
              <td>{$item['inventory']}</td>
              <td>{$item.createtime|date="Y-m-d ",###}</td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
 
                     
                  
               <if condition="$item['yid'] neq 0">  <span class="am-icon-pencil-square-o"></span><a href="{:U('item/editItem',array('itemid'=>$item['itemid']))}">编辑</a></if>
                    <?php if( $item['yid']!=0){?>
                   
                    <span class="am-icon-trash-o"></span><a href="javascript:onclick=delitem({$item['itemid']})"> 删除 </a> 
                     <?php }else{?>
                       
                       <?php }?>
                       <if condition="$item['yid'] neq 0"><if condition="$item['status'] neq 1"> <span class="am-icon-cog"></span><a target="_blank"  onclick="upshelves({$item['itemid']})">上架</a><else/><span class="am-icon-cog"></span><a target="_blank"  onclick="downshelves({$item['itemid']})">下架</a></if></if>
                     <span class="am-icon-eye"></span><a href="{:U('item/viewItem',array('itemid'=>$item['itemid']))}"target="_blank">预览</a>
                  </div>
                </div>
              </td>
            </tr>
            </foreach>
          </tbody>
        </table>
          <div class="am-cf">
  共 {$pagearr['count']}条记录

<div class="am-fr page">
    <ul class="am-pagination ">
      <li><a href="{:U('index',array('page'=>$pagearr['prevpage']))}">«</a></li>
       <?php $k=0; ?>
      <for start="$pagearr['page']" end="$pagearr['pagetotal']+1"  name='i' step="1">
         <if condition="$k lt 6">
           <li <if condition="$i eq $pagearr['page']"> class="am-active" </if>  > <a href="{:U('Item/index',array('page'=>$i))}">{$i}</a></li>
         </if>
       <?php $k+=1;  ?>
      </for>

      <li><a href="{:U('Item/index',array('page'=>$pagearr['nextpage']))}">»</a></li>
    </ul>
  </div>

</div>

      </div>

    </div>
  </div>
  <!-- content end -->
</div>
<footer>
  <hr>
  <p class="am-padding-left">© 2014 商之联.</p>
</footer>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/rem.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/respond.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.min.js"></script>
<!--<![endif]-->
<script src="{:C('SUPPLIER_ADMIN_JS')}app.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.cookie.js"></script>
<script type="text/javascript">
    function delitem (itemid) {
        var id=itemid;
        $.ajax( {
            type:"GET",
            data:{"itemid":id},
            url: "{:U('Item/delItem' )}",
            dataType:"json",
            success:function(message){
                if (message.status)
                {
                    alert(message.msg);
                     location.reload();
                 }else{
                 alert(message.msg);
                  location.reload();
                }
                }


          })
    }
//ajax 添加类目
$(function()
{
  $.ajax({
    type:'GET',
    url:"{:U('Item/Type2Brand')}",
    dataType:"json",
    success:function(message){
      $('.typetree select').append(message.string);
      $('.brandtree select').append(message.bsting);
    }
  });
})

$(function(){
  $("select[name='typeid']").change(function(){
   
  var typeid=$("select[name='typeid'] option:selected").val();
    var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 1000));
    $.cookie("typeid", typeid, { expires: date });
  });
  $("select[name='brandid']").change(function(){
  var brandid=$("select[name='brandid'] option:selected").val();
  var date = new Date();
  date.setTime(date.getTime() + (1* 60 * 1000));
    $.cookie("brandid", brandid, { expires: date });
  });
 $("input[name='yid']").change(function(){
  var yid=$("input[name='yid']").val();
  var date= new Date();
   date.setTime(date.getTime() + (1 * 60 * 1000));
    $.cookie("yid", yid, { expires: date });

});
  $("input[name='keywords']").change(function(){
  var keywords=$("input[name='keywords']").val();
  var date= new Date();
   date.setTime(date.getTime() + (1 * 60 * 1000));
    $.cookie("keywords", keywords, { expires: date });

});


});

$(function(){
  $('#filter').click(function(){
    window.location.href="{:U('Item/index')}";
  });
})


$(function(){
  $('#search').click(function(){
    window.location.href="{:U('Item/index')}";
  });
})

 function upshelves(id){

  var itemid=id;
   $.ajax( {
            type:"GET",
            data:{"itemid":itemid},
            url: "{:U('Item/upshelves' )}",
            dataType:"json",
            success:function(data){
                if (data==1)
                {
                    alert("该产品还未审核");
                    
                 }if(data==3){
                  alert("产品上架成功");
                 }
                }


          })

  

 }

 function downshelves(id){
  var res=confirm('确定要下架该产品吗');
    if(res==false){
      event.preventDefault(); 
      return false;
    }
  var itemid=id;
   $.ajax( {
            type:"GET",
            data:{"itemid":itemid},
            url: "{:U('Item/down' )}",
            dataType:"json",
            success:function(data){
                if (data==2)
                {
                    alert("未知错误");
                    
                 }if(data==3){
                  alert("商品下架成功");
                 }
                }


          })

  

 }
</script>
</body>
</html>
